package com.ytjj.common.utils;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public class SignUtil {
    public static String sign(String contentType, String source, String partentId, String partentKey,String timestamp) {
        if (StringUtils.isEmpty(contentType)) {
            contentType = "json";
        }
        Map<String, String> params = new TreeMap<>();
        params.put("contentType", contentType);
        params.put("timestamp", timestamp);
        params.put("source", source);
        params.put("partentId", partentId);
        params.put("partentKey", partentKey);
        String sign = DigestUtils.md5Hex(JSONObject.toJSONString(params).toUpperCase());
        return sign;
    }
}
